#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Untitled-1
@Time    :   2021/06/22 01:36:57
@Author  :   DJ 
@Version :   1.0
'''

# here are the description
'python解方程，简简单单'

#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sympy
import numpy as np
import math
from matplotlib.pyplot import plot
from matplotlib.pyplot import show
import matplotlib.pyplot as plt
import matplotlib
#解决无法显示中文问题，fname是加载字体路径，根据自身pc实际确定，具体请百度
zhfont1 = matplotlib.font_manager.FontProperties(fname='/System/Library/Fonts/Hiragino Sans GB W3.ttc')
 
cx = np.array([0.7, 0.9, 0])
cy = np.array([0.8, 0, 0.3])

da = 0.712
db = 0.879
dc = 0.923
 
#计算定位坐标  
def triposition(xa,ya,da,xb,yb,db,xc,yc,dc): 
    x,y = sympy.symbols('x y')
    f1 = 2*x*(xa-xc)+np.square(xc)-np.square(xa)+2*y*(ya-yc)+np.square(yc)-np.square(ya)-(np.square(dc)-np.square(da))
    f2 = 2*x*(xb-xc)+np.square(xc)-np.square(xb)+2*y*(yb-yc)+np.square(yc)-np.square(yb)-(np.square(dc)-np.square(db))
    result = sympy.solve([f1,f2],[x,y])
    locx,locy = result[x],result[y]
    return [locx,locy]
    
#解算得到定位节点坐标
[locx,locy] = triposition(cx[0],cy[0],da,cx[1],cy[1],db,cx[2],cy[2],dc)

print("result:", [locx,locy])